package a.a.a;

import net.roseboy.classfinal.util.LibUtil;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

public class B {
    public static native char[] a(String b);
    public static native void i(byte[] b);
    public static native byte[] d(byte[] b,byte[] c);
    public static native byte[] e(byte[] b,byte[] c);


    public static String runtime_win_32 = "1.dll";
    public static String runtime_win_64 = "164.dll";
    public static String runtime_linux = "1.so";
    public static String runtime_linux_armhf = "1arm.so";
    public static String runtime_linux_arm64 = "1arm64.so";

    static {
        init();
    }

    public static void init() {
        String operatingSystem = System.getProperty("os.name");
        String architecture = System.getProperty("os.arch");

        try {
            if (operatingSystem.indexOf("Windows") != -1) {
                if (architecture.equals("x86_64") || architecture.equals("amd64")) {
                    LibUtil.loadLib(runtime_win_64);
                } else {
                    LibUtil.loadLib(runtime_win_32);
                }
            } else if (operatingSystem.indexOf("Linux") != -1) {
                if (architecture.equals("x86_64") || architecture.equals("amd64")) {
                    LibUtil.loadLib(runtime_linux);
                } else if (architecture.equals("arm")) {
                    LibUtil.loadLib(runtime_linux_armhf);
                } else if (architecture.equals("aarch64")) {
                    LibUtil.loadLib(runtime_linux_arm64);
                } else {
                    LibUtil.loadLib(runtime_linux);
                }
            } else {
                LibUtil.loadLib(runtime_linux);
            }
        } catch (UnsatisfiedLinkError | IOException e) {
            if (e.getMessage().indexOf("already loaded in another classloader")!= -1) {
                System.err.println("already loaded in another classloader");
                e.printStackTrace();
//                throw e;
            } else {
                System.err.println("load so failed:" + e.getMessage());
            }
        }
    }
    public static void main(String[] args) {
        B b=new B();
        char[] cs = b.a("");
        for (char c : cs) {
            System.out.print((byte) c+" ");
        }
        System.out.println();
//        b.i("dskdjsjkds".getBytes(StandardCharsets.UTF_8));

        System.out.println(Arrays.toString(b.e("sdjbskdsk".getBytes(StandardCharsets.UTF_8),"d3sd".getBytes(StandardCharsets.UTF_8))));
//        b.i("dskdjsjkds1".getBytes(StandardCharsets.UTF_8));
        System.out.println(Arrays.toString(b.e("sdjbskdsk".getBytes(StandardCharsets.UTF_8),"d2sd".getBytes(StandardCharsets.UTF_8))));
        System.out.println("-----------------");

        System.out.println(new String(b.d(b.e("sdjbskdsk".getBytes(StandardCharsets.UTF_8),"d2sd".getBytes(StandardCharsets.UTF_8)),"d2sd".getBytes(StandardCharsets.UTF_8))));
    }
}
